﻿Imports System.Data
Imports VSModel
Imports SecurityService
Imports Cls_Common

Partial Class Control_KeyWord_Create
    Inherits System.Web.UI.UserControl
    Private Shared ReadOnly log As log4net.ILog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType)
#Region "Sub and Function "
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
        End If
    End Sub
#End Region
#Region "Event for control "
    Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Using data As New VSEntities
            'Kiem tra tu khoa da ton tai chua
            Dim q = (From p In data.Keywords Where p.Keyword1.ToUpper = txtKeyWord.Text.Trim.ToUpper Select p).FirstOrDefault
            If (q Is Nothing) Then
                Try
                    Dim kw As New Keyword
                    kw.Keyword1 = txtKeyWord.Text.Trim
                    kw.QueryString = makeURLFriendly(txtKeyWord.Text.Trim)
                    data.Keywords.AddObject(kw)

                    data.SaveChanges()
                    AddKeyWordJavascript(txtKeyWord.Text)
                    AddKeyWordJavascript(makeURLFriendly(txtKeyWord.Text.Trim))
                    kw = Nothing
                    Insert_App_Log("Insert KeyWord:" & txtKeyWord.Text.Trim & "", Function_Name.KeyWord, Audit_Type.Create, Request.ServerVariables("REMOTE_ADDR"), Session("UserName"))
                    Excute_Javascript("Alertbox('Thêm mới keyword thành công.');window.location ='../../Page/KeyWord/KeyWord.aspx';", Me.Page, True)
                Catch ex As Exception
                    log4net.Config.XmlConfigurator.Configure()
                    log.Error("Error error " & AddTabSpace(1) & Session("Username") & AddTabSpace(1) & "IP:" & GetIPAddress(), ex)
                    Excute_Javascript("Alertbox('Thêm mới keyWord thất bại.');", Me.Page, True)
                End Try
            Else
                showError.Visible = True
            End If
        End Using
    End Sub
    Protected Sub btnHuy_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnHuy.Click
        Response.Redirect("KeyWord.aspx")
    End Sub
#End Region

End Class
